home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1998 January / PC Answers Issue 49 Cover CD January 1998.iso / Apps / Director / DATA.Z / Widget Wizard.dir / WidgtBehaviors_52_vert slider.ls < prev    next >
Encoding:
Text File  |  1997-05-10  |  6.0 KB  |  154 lines

  1. property horizontal, extentSprite, hiliteMember, tracking, newLocH, newLocV, sending, dynamic, style, Addressee, name, notify_list, min, max, valrange, minScreen, maxScreen, currentScreenVal, extentlength
  2.  
  3. on getPropertyDescriptionList
  4.   set description to [:]
  5.   if the currentSpriteNum = 0 then
  6.     set memdefault to 0
  7.     set VextentSprite to 0
  8.     set topOfExtent to 0
  9.     set bottomOfExtent to 0
  10.   else
  11.     set memref to the member of sprite the currentSpriteNum
  12.     set castLibNum to the castLibNum of memref
  13.     set memdefault to member (the memberNum of member memref + 1) of castLib castLibNum
  14.     set VextentSprite to the currentSpriteNum - 1
  15.     set topOfExtent to the top of sprite VextentSprite
  16.     set bottomOfExtent to the bottom of sprite VextentSprite
  17.   end if
  18.   addProp(description, #hiliteMember, [#default: memdefault, #format: #bitmap, #comment: "Pict for Down:"])
  19.   addProp(description, #dynamic, [#default: 1, #format: #boolean, #comment: "Dynamic:"])
  20.   addProp(description, #name, [#default: "Vertical", #format: #string, #comment: "Slider Name:"])
  21.   addProp(description, #extentSprite, [#default: the currentSpriteNum - 1, #format: #integer, #comment: "Extent Sprite:"])
  22.   addProp(description, #min, [#default: topOfExtent, #format: #float, #comment: "Minimum:"])
  23.   addProp(description, #max, [#default: bottomOfExtent, #format: #float, #comment: "Maximum:"])
  24.   addProp(description, #horizontal, [#default: 0, #format: #boolean, #comment: "Horizontal (if not vertical):"])
  25.   return description
  26. end
  27.  
  28. on getBehaviorDescription
  29.   return "Enables a custom slider.  The slider handle is constrained to an 'extent' sprite.  Slider sends values as a parameter of an event (SliderSet slider_name, value)." & RETURN & "PARAMETERS:" & RETURN & "ΓÇó Pict for Down - member to represent handle while sliding." & RETURN & "ΓÇó Dynamic - if true value is sent while sliding, else value is sent when the handle is released." & RETURN & "ΓÇó Slider Name - name of slider sent along with value." & RETURN & "ΓÇó Minimum - least value slider can be set to." & RETURN & "ΓÇó Maximum - greatest value slider can be set to." & RETURN & "ΓÇó Extent Sprite - the channel number of the rect that constrains the handle." & RETURN & "ΓÇó Horizontal - Orientation of slider, can be horizontal os vertical."
  30. end
  31.  
  32. on getAssocMembers
  33.   set myPropList to [hiliteMember]
  34.   return myPropList
  35. end
  36.  
  37. on compute_val me
  38.   set val to 0.0
  39.   set val to float(the currentScreenVal of me) / float(the extentlength of me)
  40.   set val to val * the valrange of me
  41.   set val to val + the min of me
  42.   return val
  43. end
  44.  
  45. on send_the_val me, val
  46.   case the style of me of
  47.     #sendAllSprites:
  48.       sendAllSprites(#slider_set, the name of me, val)
  49.     #sendSprite:
  50.       repeat with s in the notifyList of me
  51.         sendSprite(s, #slider_set, the name of me, val)
  52.       end repeat
  53.     #call:
  54.       call(#slider_set, the notifyList of me, the name of me, val)
  55.   end case
  56. end
  57.  
  58. on beginSprite me
  59.   set the style of me to #sendAllSprites
  60.   set the sending of me to 1
  61.   set handle to the spriteNum of me
  62.   set the tracking of me to 0
  63.   set the newLocH of me to the locH of sprite handle
  64.   set the newLocV of me to the locV of sprite handle
  65.   if the horizontal of me then
  66.     set the newLocV of me to the locV of sprite the extentSprite of me
  67.     set the minScreen of me to the left of sprite the extentSprite of me
  68.     set the maxScreen of me to the right of sprite the extentSprite of me
  69.   else
  70.     set the newLocH of me to the locH of sprite the extentSprite of me
  71.     set the minScreen of me to the top of sprite the extentSprite of me
  72.     set the maxScreen of me to the bottom of sprite the extentSprite of me
  73.   end if
  74.   set the locH of sprite handle to the newLocH of me
  75.   set the locV of sprite handle to the newLocV of me
  76.   set the valrange of me to the max of me - the min of me
  77.   set the extentlength of me to the maxScreen of me - the minScreen of me
  78.   if the sending of me = 0 then
  79.     set the dynamic of me to 0
  80.   end if
  81. end
  82.  
  83. on endSprite me
  84. end
  85.  
  86. on prepareFrame me
  87.   if tracking then
  88.     set handle to the spriteNum of me
  89.     set extent to the extentSprite of me
  90.     if the horizontal of me then
  91.       set the newLocH of me to the mouseH
  92.       set the newLocV of me to the locV of sprite extent
  93.       if the newLocH of me < the left of sprite extent then
  94.         set the newLocH of me to the left of sprite extent
  95.       end if
  96.       if the newLocH of me > the right of sprite extent then
  97.         set the newLocH of me to the right of sprite extent
  98.       end if
  99.       set the currentScreenVal of me to the newLocH of me - the minScreen of me
  100.     else
  101.       set the newLocH of me to the locH of sprite extent
  102.       set the newLocV of me to the mouseV
  103.       if the newLocV of me < the top of sprite extent then
  104.         set the newLocV of me to the top of sprite extent
  105.       end if
  106.       if the newLocV of me > the bottom of sprite extent then
  107.         set the newLocV of me to the bottom of sprite extent
  108.       end if
  109.       set the currentScreenVal of me to the newLocV of me - the minScreen of me
  110.     end if
  111.     set the locH of sprite handle to the newLocH of me
  112.     set the locV of sprite handle to the newLocV of me
  113.     if the dynamic of me then
  114.       set x to compute_val(me)
  115.       send_the_val(me, x)
  116.     end if
  117.   end if
  118. end
  119.  
  120. on mouseDown me
  121.   set tracking to 1
  122.   set temp to the member of sprite the spriteNum of me
  123.   set the member of sprite the spriteNum of me to member the hiliteMember of me
  124.   set the hiliteMember of me to temp
  125. end
  126.  
  127. on mouseUp me
  128.   set tracking to 0
  129.   set temp to the member of sprite the spriteNum of me
  130.   set the member of sprite the spriteNum of me to member the hiliteMember of me
  131.   set the hiliteMember of me to temp
  132.   if the sending of me then
  133.     set x to compute_val(me)
  134.     send_the_val(me, x)
  135.   end if
  136. end
  137.  
  138. on mouseUpOutSide me
  139.   set tracking to 0
  140.   set temp to the member of sprite the spriteNum of me
  141.   set the member of sprite the spriteNum of me to member the hiliteMember of me
  142.   set the hiliteMember of me to temp
  143.   if the sending of me then
  144.     set x to compute_val(me)
  145.     send_the_val(me, x)
  146.   end if
  147. end
  148.  
  149. on mouseEnter me
  150. end
  151.  
  152. on mouseLeave me
  153. end
  154.